package com.scheduling.order.entity.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 订单项数据传输对象
 *
 * @author 开发团队
 * @since 2025-05-29
 */
@Data
@Schema(description = "订单项信息")
public class OrderItemDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    @Schema(description = "订单项ID")
    private String orderItemId;

    @Schema(description = "订单ID")
    private String orderId;

    @Schema(description = "产品ID", required = true)
    @NotBlank(message = "产品ID不能为空")
    private String productId;

    @Schema(description = "产品名称")
    private String productName;

    @Schema(description = "产品描述")
    private String productDescription;

    @Schema(description = "数量", required = true)
    @NotNull(message = "数量不能为空")
    @Min(value = 1, message = "数量必须大于0")
    private Integer quantity;

    @Schema(description = "优先级(1-高,2-中,3-低)", required = true)
    @NotNull(message = "优先级不能为空")
    @Min(value = 1, message = "优先级必须在1-3之间")
    @Max(value = 3, message = "优先级必须在1-3之间")
    private Integer priority;

    @Schema(description = "优先级描述")
    private String priorityDescription;

    @Schema(description = "已生产数量")
    private Integer producedQuantity;

    @Schema(description = "状态")
    private String status;

    @Schema(description = "状态描述")
    private String statusDescription;

    @Schema(description = "完成率")
    private Double completionRate;

    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    /**
     * 获取优先级描述
     */
    public String getPriorityDescription() {
        if (priority == null) {
            return null;
        }
        switch (priority) {
            case 1:
                return "高";
            case 2:
                return "中";
            case 3:
                return "低";
            default:
                return "未知";
        }
    }

    /**
     * 计算完成率
     */
    public Double getCompletionRate() {
        if (quantity == null || quantity == 0 || producedQuantity == null) {
            return 0.0;
        }
        return Math.round((producedQuantity.doubleValue() / quantity.doubleValue()) * 100.0 * 100.0) / 100.0;
    }
} 